import { Component, OnInit, ViewChild, Output, Input, EventEmitter } from '@angular/core';
import { NzMessageService } from 'ng-zorro-antd';
import { DomSanitizer } from '@angular/platform-browser';
import { LocalStorage } from '@core/local.storage';
import { _HttpClient } from '@delon/theme';
import { DatePipe } from '@angular/common';
import { environment } from '../../../../../environments/environment';
import { TableCheckPageComponent } from '../../../../layout/components/tableCheckPage.component';

@Component({
    selector: 'app-detailmodal',
    templateUrl: './detailmodal.component.html',
    styleUrls: ['./tctj_statistics.component.less']
})
export class DetailModalComponent implements OnInit {
    @ViewChild('tcp', { static: true }) tcp: TableCheckPageComponent;
    @Input() apiUrl: any;
    @Input() width: any;
    @Input() responseData: any;
    @Input() popTitle: any;
    @Input() paramType: any;
    @Input() month: any
    @Output() public closeModal = new EventEmitter();
    @Output() public reloadData = new EventEmitter();

    Visible = false;
    operaData: any = {};
    objData: any = {};
    thisData: any = { 'count': 0, 'id': [] };
    problemData: any = {};
    processesData = [];
    handlesData = [];
    headData = [];
    plainData = [];
    tableScroll = { x: '2000px' };

    constructor(
        public ls: LocalStorage
    ) { }

    ngOnInit() {
        if (!this.width) {
            this.width = '500';
        }
        setTimeout(() => {
            this.Visible = true;
            this.headData = [
                { "name": "作业类型", "width": "15%" },
                { "name": "作业日期", "width": "6%" },
                { "name": "作业项目" },
                { "name": "作业级别", "width": "6%" },
                { "name": "作业地点", "width": "6%" },

                { "name": "作业开始时间", "width": "6%" },
                { "name": "作业结束时间", "width": "6%" },
                { "name": "作业线路", "width": "6%" },
                { "name": "作业负责人", "width": "6%" },
                { "name": "作业行别", "width": "6%" }
            ];
            this.plainData = [
                "vcType", "dtWorkday", "vcProject", "vcLevel", "vcWorkplace",
                "vcSkywinstime", "vcSkywinetime", "vcSgroute", "vcWaperson", "vcSgdirectoryname"
            ];
            this.loadList();
        }, 200);
    }
    loadList() {
        const data = JSON.parse(this.responseData.split('|')[0]);
        let param = '&monthStr=' + this.month;
        switch (this.paramType) {
            case 'line':
                param += '&line=' + data.line;
                switch (this.responseData.split('|')[1]) {
                    case 'planFinish':
                        param += '&finish=1';
                        break;
                    case 'planUnfinish':
                        param += '&finish=0';
                        break;
                }
                break;
            case 'org':
                param += '&orgName=' + data.orgName;
                switch (this.responseData.split('|')[1]) {
                    case 'planFinish':
                        param += '&finish=1';
                        break;
                    case 'planUnfinish':
                        param += '&finish=0';
                        break;
                }
                break;
            case 'primary':
                param += '&orgName=' + data.orgName;
                switch (this.responseData.split('|')[1]) {
                    case 'primaryCount':
                        param += '&primary=1';
                        break;
                    case 'assistCount':
                        param += '&primary=0';
                        break;
                }
                break;
            case 'primaryUnit':
                param += '&orgType=' + data.orgName;
                break;
            case 'level':
                param += '&level=' + data.level;
                switch (this.responseData.split('|')[1]) {
                    case 'planFinish':
                        param += '&finish=1';
                        break;
                    case 'planUnfinish':
                        param += '&finish=0';
                        break;
                }
                break;
            case 'win':
                param += '&line=' + data.line + '&skyType=' + data.skyType;
                switch (this.responseData.split('|')[1]) {
                    case 'planFinish':
                        param += '&finish=1';
                        break;
                    case 'planUnfinish':
                        param += '&finish=0';
                        break;
                }
                break;
        }
        this.tcp.loadList(this.apiUrl, param);
    }
    Ok() {
        this.Cancel();
    }
    Cancel() {
        this.Visible = false;
        setTimeout(() => {
            this.closeModal.emit();
        }, 200);
    }
}